<template>
  <el-breadcrumb class="breadcrumb" separator="/">
    <transition-group name="breadcrumb">
      <el-breadcrumb-item v-for="(item, index) in breadcrumData" :key="index">
        <span v-if="index == breadcrumData.length - 1" class="no-redirect">{{
          generateTitle(item.meta.title)
        }}</span>
        <a v-else class="redirect" @click.prevent="onLinkClick(item)">
          {{ generateTitle(item.meta.title) }}
        </a>
      </el-breadcrumb-item>
    </transition-group>
  </el-breadcrumb>
</template>

<script>
import { generateTitle } from '../../utils/i18n'
export default {
  data() {
    return {
      breadcrumData: [],
    };
  },
  watch: {
    $route: {
      handler(newRouter) {
        this.breadcrumData = this.$route.matched.filter((item) => {
          return item.meta && item.meta.title;
        });
      },
      immediate: true,
    },
  },
  methods: {
    onLinkClick(item) {
      this.$router.push(item.path);
    },
    generateTitle,
  },
};
</script>

<style scoped lang='scss'>
.breadcrumb {
  display: inline-block;
  font-size: 14px;
  line-height: 50px;
  margin-left: 8px;

  ::v-deep .no-redirect {
    color: #97a8be;
    cursor: text;
  }
}
</style>
